package stcpscheculer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class ScheduleInterface {

	public static void readtxt() {
	
		String fname = "data.txt";
		String line;
		
		
		File confFile = new File(fname);
		FileReader Reader = null;
	    try
	    {
	    	Reader = new FileReader(fname);
	    } 
	    catch (FileNotFoundException e) 
	    {  
	        System.out.println( "File "+ fname +" not found" );
	        e.printStackTrace();
	    }
	    BufferedReader br = new BufferedReader(Reader);
            int drivers=0,buses=0;
	    try
	    {
	        while( (line = br.readLine()) != null )
		    {
                       
		      System.out.println( line );
                        if(line.equals("*setBuses*"))
                        {
                            System.out.println( "OK1" );
                          line = br.readLine();
                           buses = Integer.parseInt(line);
                          Configuration.setBuses(buses);
                          
                        }
                        else if(line.equals("*setDrivers*"))
                            {
                                 System.out.println( "OK2" );
                          line = br.readLine();
                          drivers = Integer.parseInt(line);
                          Configuration.setDrivers(drivers);
                        
                        }
                        else if(line.equals("*setTimeSlot*"))
                            {
                                System.out.println( "OK3" );
                          line = br.readLine();
                          int timeslot = Integer.parseInt(line);
                          Configuration.setTimeSlot(timeslot);
                        }
                 
                        else if(line.equals("*setPopulationSize*"))                            {
                          line = br.readLine();
                          int popsize = Integer.parseInt(line);
                          Configuration.setPopulationSize(popsize);
                        }
                        else if(line.equals("*setMaxGenerations*"))
                            {
                          line = br.readLine();
                          int maxgen = Integer.parseInt(line);
                          Configuration.setMaxGenerations(maxgen);
                        }
                        else if(line.equals("*setDesiredFA*"))
                            {
                          line = br.readLine();
                          int desfa = Integer.parseInt(line);
                          Configuration.setMaxGenerations(desfa);
                        }
                        else if(line.equals("*setF1*"))
                            {
                          line = br.readLine();
                          float f1 = Float.parseFloat(line);
                          Configuration.setF1(f1);
                        }
                        else if(line.equals("*setF2*"))
                            {
                          line = br.readLine();
                          float f2 = Float.parseFloat(line);
                          Configuration.setF1(f2);
                        }
                        else if(line.equals("*setF3*"))
                            {
                          line = br.readLine();
                          float f3 = Float.parseFloat(line);;
                          Configuration.setF1(f3);
                        }
                        else if(line.equals("*setF4*"))
                            {
                          line = br.readLine();
                          float f4 = Float.parseFloat(line);
                          Configuration.setF1(f4);
                        }
                        else if(line.equals("*setF5*"))
                            {
                          line = br.readLine();
                          float f5 = Float.parseFloat(line);
                          Configuration.setF1(f5);
                        }
                        else if(line.equals("*Buses*"))
                            {
                                
                             Configuration.setBusesArr();
                               for(int i=0;i<buses;i++)
                               {
                                  line = br.readLine();
                                  int busid = Integer.parseInt(line); 
                                  line = br.readLine();
                                  String bustype=line;
                                  Configuration.busesArr[i] = new Bus(busid, bustype);
                                 }
                  }
                        
                        
                        else if(line.equals("*Drivers*"))
                        {
                            Configuration.setDriversArr();
                            for(int i=0;i<drivers;i++)
                               {
                                  line = br.readLine();
                                  int driverid = Integer.parseInt(line); 
                                  line = br.readLine();
                                  String delims = "[,]";
                                  String[] tokens = line.split(delims);
                                  Set<String> types = new HashSet<String>();
                                  for (String s : tokens ) {  
                                     types.add(s);
                                     System.out.println(s);
                                     
                                    } 
                                  line = br.readLine();
                                  String delims2 = "[,]";
                                  String[] tokens2 = line.split(delims2);
                                  Set<String> types2 = new HashSet<String>();
                                  for (String s : tokens2 ) {  
                                     types2.add(s);
                                     System.out.println(s);
                                    } 
                                  line = br.readLine();
                                  int drivermaxtime = Integer.parseInt(line);
                                  line = br.readLine();
                                  System.out.println( line );
                                  String delims3 = "[,]";
                                  String[] tokens3 = line.split(delims3);
                                 
                            
                                    
                                  Pair par = new Pair(Integer.parseInt(tokens3[0]), Integer.parseInt(tokens3[1]));
                                  
                                  
                                  Configuration.driversArr[i] = new Driver(driverid, types,types2,drivermaxtime,par);
                                 }
                        }
                        
		    }
	    } 
	    catch (IOException e) {
	        System.out.println(e.getMessage());
	    }
		
	}
	
}
